<?php
/**
 * Patient Signal upload form 6, upload file page. Used in upload action in PatientSignalController.
 *
 * @package   views
 * @subpackage patientSignal
 * @since     1.0
 * @filesource
 */
?>
<h1>Upload Signals for <?php echo $organization->name;?></h1>
<div id="upload-signal-step-bar">
	<ul class="upload-signal-steps">
		<li>Step 1</li>
		<li>Step 2</li>
		<li>Step 3</li>
		<li>Step 4</li>
		<li>Step 5</li>
		<li class="current-step">Step 6</li>
	</ul>
	<div class="clear"></div>
</div>
<div class="clear"></div>
<h2>Step 6 - Upload Signal Files</h2>
<div class="form">
<?php
Yii::app()->clientScript->registerCoreScript('jquery');
$this->widget('ext.plupload.PluploadWidget', array(
	'config' => array(
		//'runtimes' => 'html5',
		'url' => $this->createUrl('patientSignal/uploadFilesPlupload'),
		//'max_file_size' => str_replace("M", "mb", ini_get('upload_max_filesize')),
		'max_file_size' => '100mb',
		'chunk_size' => '1mb',
		'unique_names' => true,
		'filters' => array(array('title' => 'SMR Files', 'extensions' => 'smr'),),
		//'browse_button'=>'uploadButton',
		'language' => 'en-smr',
		'max_file_number' => 6,
		'autostart' => false,
		'jquery_ui' => true,
		'browse_button'=>'uploader_browse',
		'reset_after_upload' => false,
		//using this flag to disable CSRF validation for uploads
		'headers'=>array('XUPLOAD'=>"true"),
	),
	'callbacks' => array(
		'FileUploaded' => 'function(up,file,response){
		up.refresh();
		jQuery.post( "'.$this->createUrl('patientSignal/uploadFilesInfo').'", {id:file.id,name:file.name,'.Yii::app()->request->csrfTokenName.':"'.Yii::app()->request->csrfToken.'"}, 
		function(data, textStatus, jqXHR){
			var fileContainer=$("#uploaded-files-container");
			if(data.success){
				var newLine=$("<div></div>").appendTo(fileContainer);
				var checkbox=$("<input />").attr("id","PatientSignalUpload6_signalFileIds_"+data.fileId)
							.attr("type","checkbox")
							.attr("name","PatientSignalUpload6[signalFileIds][]")
							.attr("value",data.fileId).attr("checked","checked")
							.appendTo(newLine);
				var label=$("<label></label>")
							.attr("for","PatientSignalUpload6_signalFileIds_"+data.fileId)
							.html(" "+data.filename)
							.appendTo(newLine);
			}else{
				var message=data.message || "Unknown Error happened when processing file.";
				var errorMessage=$("<div></div>").appendTo(fileContainer).addClass("errorMessage").html(message);
				window.setTimeout(function(){
					errorMessage.fadeOut(2000);
				},4000);
			}
		},"json" );
		}',
		),
	'id' => 'uploader'
	)
);
?>

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'patient-signal-upload6-upload6-form',
	'enableAjaxValidation'=>FALSE,
)); ?>

	
	<?php echo $form->errorSummary($model); ?>
<fieldset>
	<legend>Uploaded Files</legend>
	<div class="row checkbox-group">
		<div class="hint">Please choose the files you wish to add to the patient signal.</div>
		<div id="uploaded-files-container">
		<?php echo $form->checkBoxList($model,'signalFileIds',$sessionFiles,array('uncheckValue'=>null)); ?>
		</div>
		<?php //echo $form->error($model,'signalFileIds'); ?>		
	</div>
</fieldset>
	<div class="row buttons">
		<?php echo CHtml::submitButton('Previous',array('name'=>'upload_action')); ?>
		<?php echo CHtml::submitButton('Save',array('name'=>'upload_action')); ?>
		<?php echo CHtml::submitButton('Cancel',
			array('onclick'=>'window.location.href="'.$this->createUrl('cancelUpload').'";return false',
				'confirm'=>'Cancel upload and delete all uploaded data and files?'
			));?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->